#include <TaobaoUtils.h>
#include <cstdio>
#include <string>
#include <sys/stat.h>

/*
 * Class:     com_mango_config_DeviceConfig
 * Method:    nGetBoot
 * Signature: ()Ljava/lang/String;
 */
extern "C" JNIEXPORT jstring JNICALL Java_com_mango_config_DeviceConfig_nGetBoot
  (JNIEnv *env, jclass) {
    FILE *fp = fopen("/proc/sys/kernel/random/boot_id", "r"); char boot[37];
    if (fp == nullptr)
    //"Error opening file"
    boot[0]= '\0'; else { fgets(boot,37,fp); fclose(fp);
    }
    std::string sboot = boot;
    return env->NewStringUTF(sboot.c_str());
  }

/*
 * Class:     com_mango_config_DeviceConfig
 * Method:    nGetUpdate
 * Signature: ()Ljava/lang/String;
 */
extern "C" JNIEXPORT jstring JNICALL Java_com_mango_config_DeviceConfig_nGetUpdate
  (JNIEnv *env, jclass) {
    struct stat sb{};
    int updates = 0, updatens = 0;
    if (stat("/data/data", &sb) == -1) { //获取失败
    } else {
    updatens = (int) sb.st_atim.tv_nsec;
    updates = (int) sb.st_atim.tv_sec;
    }
    std::string idRes = std::to_string(updates) + "." + std::to_string(updatens);
    return env->NewStringUTF(idRes.c_str());
  }